package com.designoutput.service
{
	import com.designoutput.ui.GalleryCanvas;
	
	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	public class CardService extends ServiceBase
	{
		//Singleton
		private static var _instance:CardService;
		private static var _allowInstantiation:Boolean = false;
		
		public function CardService()
		{
			if(!_allowInstantiation)
				throw new Error("This class is singleton, use the static property instance.");
		}
		
		public static function get instance():CardService {
			if(_instance == null)
			{
				_allowInstantiation = true;
				
				_instance = new CardService();
				
				_allowInstantiation = false;
			}
			
			return _instance;
		}
		//
		
		public static const SAVE_CARD:String="saveCard.php";
		public static const OPEN_CARD:String="openCard.php";
		
		public function saveCard(id:int, name:String, cardXML:String, base64PNGThumb:String, onComplete:Function = null, onError:Function = null):void
		{
			call(SAVE_CARD, { id: id, name: name, cardXML: cardXML, base64PNGThumb: base64PNGThumb }, onComplete, onError);
		}
		
		public function openCard(id:int, onComplete:Function = null, onError:Function = null):void
		{
			call(OPEN_CARD, { id: id }, onComplete, onError);
		}
	}
}